package cn.golxen.rsms.controller;

import cn.golxen.rsms.bean.bo.PlaceOrderBo;
import cn.golxen.rsms.bean.bo.PlaceOrderByAuthCodeBo;
import cn.golxen.rsms.bean.entity.PayLog;
import cn.golxen.rsms.bean.entity.PayRegister;
import cn.golxen.rsms.commons.Result;
import cn.golxen.rsms.commons.annotation.AddLog;
import cn.golxen.rsms.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/pay")
public class PayController {
    @Autowired
    PayService payService;

    @PostMapping(value = "/add/payRegister")
    public Result addPayRegister(@RequestBody PayRegister payRegister){
        return Result.successResult(payService.addPayRegister(payRegister));
    }

    @PostMapping(value = "/del/payRegister")
    public Result delPayRegister(@RequestBody List<PayRegister> payRegisters){
        return Result.successResult(payService.delPayRegister(payRegisters));
    }

    @GetMapping(value = "/get/payRegister/{storeId}")
    public Result  getPayRegister(@PathVariable int storeId){
        return Result.successResult(payService.getPayRegister(storeId));
    }

    @AddLog(type = "Native下单")
    @PostMapping(value = "/placeOrder/native")
    public Result placeOrderByNative(@RequestBody PlaceOrderBo placeOrderBo){

        return Result.successResult(payService.placeOrderByNative(placeOrderBo));
    }

    @PostMapping(value = "/queryOrder")
    public Result queryOrderNative(@RequestBody PlaceOrderBo placeOrderBo){
        return Result.successResult(payService.queryOrder(placeOrderBo));
    }

    @GetMapping(value = "/get/payingOrder/{storeId}")
    public Result getPayingOrder(@PathVariable int storeId){
        return Result.successResult(payService.getPayingCodeList(storeId));
    }

    @AddLog(type = "付款码支付")
    @PostMapping(value = "/placeOrder/authCode")
    public Result placeOrderByAuthCode(@RequestBody PlaceOrderByAuthCodeBo placeOrderByAuthCodeBo){
        return Result.successResult(payService.placeOrderByAuthCode(placeOrderByAuthCodeBo));
    }

    @AddLog(type = "快捷收款")
    @PostMapping(value = "/placeOrder/quick")
    public Result placeOrderByQuick(@RequestBody PayLog placeOrder){
        return Result.successResult(payService.placeOrderByQuick(placeOrder));
    }

    @GetMapping(value = "/get/lastOrderByDone/{storeId}")
    public Result getLastOrderByDone(@PathVariable int storeId){
        return Result.successResult(payService.getLastOrderByDone(storeId));
    }

}
